// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import { userInfo } from './api'
import $http from './api/index.js'
import VueLazyLoad from 'vue-lazyload'
import $ from 'jquery'
import Vuex from 'vuex'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import MintUi from 'mint-ui'
import YDUI from 'vue-ydui'; /* 相当于import YDUI from 'vue-ydui/ydui.rem.js' */
import 'mint-ui/lib/style.css'
import 'vue-ydui/dist/ydui.rem.css';

require('swiper/dist/css/swiper.css')
require('./assets/css/base.css'); //全局引入
Vue.use(VueAwesomeSwiper)
Vue.use(MintUi)
Vue.use(Vuex)
Vue.use(YDUI);
Vue.use(VueLazyLoad, {
	error: require('./assets/images/err.png'),
	loading: require('./assets/images/loading.gif'),
})
const vuex_store = new Vuex.Store({
	state: {
		user_name: ""
	},
	mutations: {
		showUserName(state) {
			alert(state.user_name);
		}
	}
})
const whiteList = ['/wx/home', '/wx/register', '/wx/login', '/wx/yonghuxieyi', '/wx/findPassword', '/wx/category', '/wx/searchPage', '/wx/detail', '/wx/test', '/wx/aboutUs', '/wx/logistics', '/wx/guanZhuErWeiMa', '/wx/guanZhuErWeiMa2', '/wx/orders'] // 不需要登陆的页面

router.beforeEach(function(to, from, next) {
	console.log('localStorage.Authorization', localStorage.Authorization)
	userInfo(localStorage.Authorization, function(res) {
		console.log('router-res', res)
		if(res.code == 101 || res.code == 403) {
			let zhengzestr = '/'+to.path.split('/')[1]+'/'+to.path.split('/')[2]
			console.log('zhengzestr', zhengzestr)
			if(whiteList.indexOf(zhengzestr) !== -1) {
				next()
			} else {
				next('/wx/login')
			}
		}else {
			next()
		}
	}, function(res) {
	})
})

Vue.config.productionTip = false
Vue.prototype.$http = $http
Vue.prototype.root = $http.root
/* eslint-disable no-new */
new Vue({
	el: '#app',
	store: vuex_store, //注入到vue
	router,
	components: {
		App
	},
	template: '<App/>'
})